//related to chat_cell.ui
var root = ui("$");
;// $是这个ui文件根节点组件的通配符，如果指定组件的id，也可以用id来获取对象

var page = sm("do_Page");
var checkedLayout = ui("do_ALayout_3");
var checkedImage = ui("checkbox");
var plus = ui("do_Button_1");
var subtract = ui("do_Button_2");
var count = ui("count_label");
var price = ui("price_label");
var marketPrice = ui("marketPriceLabel");
var do_ALayout_4 = ui("do_ALayout_4");
var qqmath = require("util/qqmath");
var openHelper = require("helper/open");
var mallUrl = require("url/mall");
root.setMapping({
	"photo_imageview.source" : "img",
	"name_label.text" : "name",
	"spec_label.text" : "spec",
	"price_label.text" : "price",
	"marketPriceLabel.text" : "marketPrice",
	"do_Button_2.fontColor" : "subtractColor",
	"checkbox.source" : "checked",
	"checkbox.tag":"supplierId",
	"do_ALayout_3.tag":"supplierType",
	"count_label.text" : "quantity",
	"do_ALayout_4.tag" : "productId",
	"count_label.tag" : "id"// 利用一个组件的tag属性来记录当前cell的索引
});
root.on("dataRefreshed", function(){
	price.text = qqmath.getDight(price.text,2)+'';
	marketPrice.text = qqmath.getDight(marketPrice.text,2)+'';
});
checkedLayout.on("touch", function() {
	if (checkedImage.source == deviceone.checked) {
		checkedImage.source = deviceone.unchecked;
	} else {
		checkedImage.source = deviceone.checked;
	}
	fireMyorder();
})

plus.on("touch", function() {
	var c = count.text;
	if(c>=1){
		subtract.fontColor = "313131FF";
	}
	count.text = (c * 1) + 1;
	fireMyorder();
});
subtract.on("touch", function() {
	var c = count.text;
	c = c - 1;
	if (c <= 1){
		c = 1;
		subtract.fontColor = "C0C0C0FF";
	}
	count.text = c;
	fireMyorder();
});

function fireMyorder() {
	var d = {
		"id" : count.tag,
		"quantity":count.text,
		"checked" : checkedImage.source,
		"supplierId": checkedImage.tag,
		"supplierType":checkedLayout.tag
	};
	page.fire("myorder", d);
}

do_ALayout_4.on("touch","",3000 ,function(){
	openHelper.open("source://view/mall/product/main.ui",{id:do_ALayout_4.tag},"","pay_product_back");
});